/*
 *    Copyright (c) 2018-2025, boss All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the boss developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: boss
 */

package com.hopes.bizz.protocol.hj212.controller;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hopes.bizz.protocol.hj212.dto.ProtocolHj212MqLogDTO;
import com.hopes.bizz.protocol.hj212.entity.ProtocolHj212MqLogEntity;
import com.hopes.bizz.protocol.hj212.service.ProtocolHj212MqLogService;
import com.hopes.boss.common.core.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * hj212协议转发mq消息日志
 *
 * @author daijie
 * @date 2023-06-08 13:48:16
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/Hj212MqLog")
@Tag(description = "Hj212MqLog", name = "hj212协议转发mq消息日志管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class ProtocolHj212MqLogController {

    private final ProtocolHj212MqLogService protocolHj212MqLogService;

    /**
     * 分页查询
     *
     * @param page 分页对象
     * @param protocolHj212MqLog hj212协议转发mq消息日志
     * @return
     */
    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('hj212_mq_log_view')")
    public R getProtocolHj212MqLogPage(Page page, ProtocolHj212MqLogDTO protocolHj212MqLog) {
        LambdaQueryWrapper<ProtocolHj212MqLogEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.orderByDesc(ProtocolHj212MqLogEntity::getSendTime);
        wrapper.eq(ObjectUtil.isNotNull(protocolHj212MqLog.getSuccess()),ProtocolHj212MqLogEntity::getSuccess, protocolHj212MqLog.getSuccess());

        wrapper.ge(ObjectUtil.isNotNull(protocolHj212MqLog.getBeginTime()), ProtocolHj212MqLogEntity::getSendTime, protocolHj212MqLog.getBeginTime());
        wrapper.le(ObjectUtil.isNotNull(protocolHj212MqLog.getEndTime()), ProtocolHj212MqLogEntity::getSendTime, protocolHj212MqLog.getEndTime());
        return R.ok(protocolHj212MqLogService.page(page, wrapper));
    }

    /**
     * 通过id查询hj212协议转发mq消息日志
     *
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询", description = "通过id查询")
    @GetMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('hj212_mq_log_view')")
    public R getById(@PathVariable("id") Long id) {
        return R.ok(protocolHj212MqLogService.getById(id));
    }
}